<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="js/jquery-3.5.1.min.js"></script>
<title>管理员界面</title>
<style type="text/css">
.table1 {
	margin: 15px;
	padding: 5px;
}

.input {
	font-size: 20px;
}

.button {
	background-color: green;
	width:100%;
	height:100%;
}

.table2 {
	margin: 15px;
	border-color: red;
}
</style>
</head>
<body>
	<jsp:include page="Admin_header.jsp"></jsp:include>
	<form action="AdminServlet" method="post" id="tjform">
		<input type="hidden" value="tInsert" name="method">
		<header>添加教师</header>
		<table class="table1" border="1">
			<tr>
				<td>工号</td>
				<td>密码</td>
				<td>姓名</td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td><input type="text" class="input" name="number"></td>
				<td><input type="password" class="input" name="password"></td>
				<td><input type="text" class="input" name="name"></td>
				<td><input type="checkbox" value="Set_Manager" name="isAdmin" />管理员</td>
				<td><button id="tijiao">添加</button></td>
			</tr>
		</table>
	</form>
	<table class="table2" border="1">
		<thead>
			<tr>
				<td width="150px">工号</td>
				<td width="150px">名字</td>
				<td width=150px>是否为管理员</td>
			</tr>
		</thead>
		<tbody id="tbd">

		</tbody>
	</table>
</body>
<script>
	$(function() {
		getTeacherDetail();
	})

	function getTeacherDetail() {
		$.ajax({
			url : "${pageContext.request.contextPath}/ListAdminServlet",
			type : "GET",
			data : {},
			dataType : "json",
			success : function(data) {
				var tbody = document.getElementById('tbd');
				for (var i = 0; i < data.length; ++i) {
					var tr = document.createElement('tr');
					tbody.appendChild(tr);
					for ( var k in data[i]) {
						var td = document.createElement('td');
						tr.appendChild(td);
						td.innerHTML = data[i][k];
					}
					var td = document.createElement('td');
					tr.appendChild(td);
					td.innerHTML = "是";
				}
			},
			error : function() {
				alert('获取教师信息失败！');
			}
		});
		$.ajax({
			url : "${pageContext.request.contextPath}/ListTeacherServlet",
			type : "GET",
			data : {},
			dataType : "json",
			success : function(data) {
				var tbody = document.getElementById('tbd');
				for (var i = 0; i < data.length; ++i) {
					var tr = document.createElement('tr');
					tbody.appendChild(tr);
					for ( var k in data[i]) {
						var td = document.createElement('td');
						tr.appendChild(td);
						td.innerHTML = data[i][k];
					}
					var td = document.createElement('td');
					tr.appendChild(td);
					td.innerHTML = "否";
				}
			},
			error : function() {
				alert('获取教师信息失败！');
			}
		});
	}
	
	$('#tijiao').click(function(){
		$('#tjform').submit();
	});
</script>
</html>